package com.yfbao.horizon.schedule.tk.conf;

import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class MyConditionalOnProperty extends SpringBootCondition {

    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String metricEnable = context.getEnvironment().getProperty("seeyon.system.metric");
        String redisType = context.getEnvironment().getProperty("spring.redis.client-type");

        // 判断不同属性的值
        if("true".equals(metricEnable) && (redisType ==null  || "lettue".equals(redisType))){
            return ConditionOutcome.match("Conditions met: seeyon.system.metric=true, spring.redis.client-type=lettue");
        }else {
            return ConditionOutcome.noMatch("Conditions not met");
        }
    }
}
